package com.lfg.leetcode.leetcode1500;


import com.alibaba.fastjson.JSON;

public class No1567getMaxLen {
    public static void main(String[] args) {
        System.out.println(JSON.toJSONString(getMaxLen(new int[]{0, 1, -2, -3, -4})));
    }


    public static int getMaxLen(int[] nums) {
        int ret = 0;
        int pl = 0;
        int nl = 0;

        for (int num : nums) {
            if (num == 0) {
                pl = nl = 0;
            } else if (num > 0) {
                nl = nl > 0 ? nl + 1 : 0;
                pl++;
            } else {
                int tmpl = nl;
                nl = pl + 1;
                pl = tmpl > 0 ? tmpl + 1 : 0;
            }
            ret = Math.max(ret, pl);
        }
        return Math.max(ret, pl);
    }
}

